updating oE peek

Reading from Memory

peek

<built-in> function peek(object addr_n_length) 

fetches a byte, or some bytes, from an address in memory.

Parameters:
  1. addr_n_length : an object, either of
    • an atom addr -- to fetch one byte at addr, or
    • a pair {addr,len} -- to fetch len bytes at addr
Returns:

An object, either an integer if the input was a single address, or a sequence of integers if a sequence was passed. In both cases, integers returned are bytes, in the range 0..255.

Errors:

Peeking in memory you don't own may be blocked by the OS, and cause a machine exception. If you use the define safe these routines will catch these problems with a EUPHORIA error.

When supplying a {address, count} sequence, the count must not be negative.

Comments:

Since addresses are 32-bit numbers on 32-bit architectures, they can be larger than the largest value of type integer (31-bits). Variables that hold an address should therefore be declared as atoms.

It is faster to read several bytes at once using the second form of peek than it is to read one byte at a time in a loop. The returned sequence has the length you asked for on input.

Remember that peek takes just one argument, which in the second form is actually a 2-element sequence.

Example 1:
-- The following are equivalent: 
-- first way 
s = {peek(100), peek(101), peek(102), peek(103)} 
 
-- second way 
s = peek({100, 4}) 
See Also:

Using Data Bytes, poke, peeks, peek4u, allocate, free, peek2u

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu